﻿using MediatR;
using SystemMHB.API.Application.Command.SupplierCommand;
using SystemMHB.Domian;
using SystemMHB.Infrstructer.Interface;

namespace SystemMHB.API.Application.CommandHandlers.SupplierCommandHandlers
{
    public class AddSupplierCommandHandler : IRequestHandler<AddSupplierCommand, int>
    {
        /// <summary>
        /// 供应商仓储接口
        /// </summary>
        ISupplierRepository supRep;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="supRep">供应商仓储接口</param>
        public AddSupplierCommandHandler(ISupplierRepository supRep)
        {
            this.supRep = supRep;
        }

        public async Task<int> Handle(AddSupplierCommand request, CancellationToken cancellationToken)
        {
            request.IsDel = false;
            request.AddName = "张三";
            request.AddTime = DateTime.Now.ToUniversalTime();
            return await supRep.AddAsync(new Domian.Supplier()
            {
                supplierID = request.supplierID,
                supplierNumber = request.supplierNumber,
                supplierName = request.supplierName,
                supplierType = request.supplierType,
                supplierPrincipal = request.supplierPrincipal,
                supplierPhone = request.supplierPhone,
                IsDel = request.IsDel,
                AddName = request.AddName,
                AddTime = request.AddTime
            });
        }
    }
}
